package com.cuotibao.zhuoxiao.basics.utils;

import android.graphics.Bitmap;
import android.os.Message;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

/**
 * @author hdx on 2019/5/6.
 */
public class MyWebChromeClient extends WebChromeClient {
    // 网页的加载进度
    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        super.onProgressChanged(view, newProgress);
    }

    // 接收到网页的 title
    @Override
    public void onReceivedTitle(WebView view, String title) {
        super.onReceivedTitle(view, title);
    }

    // 接收到网页的 icon
    @Override
    public void onReceivedIcon(WebView view, Bitmap icon) {
        super.onReceivedIcon(view, icon);
    }

    @Override
    public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) {
        super.onReceivedTouchIconUrl(view, url, precomposed);
    }

    // 当 H5 页面中点击播放的 flash video 的全屏按钮时，会调用这个方法
    @Override
    public void onShowCustomView(View view, CustomViewCallback callback) {
        super.onShowCustomView(view, callback);
    }

    // 与 onShowCustomView() 对应的取消全屏时会调用的方法
    @Override
    public void onHideCustomView() {
        super.onHideCustomView();
    }

    @Override
    public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
        super.onShowCustomView(view, requestedOrientation, callback);
    }

    // http://www.cnblogs.com/ufreedom/p/4229590.html
    // 当创建新的 Window 时会调用此方法
    @Override
    public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
        return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg);
    }

    // 和 onCreateWindow() 方法对应的，关闭 Window
    @Override
    public void onCloseWindow(WebView window) {
        super.onCloseWindow(window);
    }

    // 当 WebView 获取焦点时会调用此方法
    @Override
    public void onRequestFocus(WebView view) {
        super.onRequestFocus(view);
    }

    // 在 Js 代码中弹出 Alert 窗口时会调用此方法
    @Override
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
        return super.onJsAlert(view, url, message, result);
    }

    // 在 Js 代码中弹出 Confirm 窗口时会调用此方法
    @Override
    public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
        return super.onJsConfirm(view, url, message, result);
    }

    // 在 Js 代码中弹出 Prompt 窗口时会调用此方法
    @Override
    public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
        return super.onJsPrompt(view, url, message, defaultValue, result);
    }

    // 在 Js 加载之前会调用此方法
    @Override
    public boolean onJsBeforeUnload(WebView view, String url, String message, JsResult result) {
        return super.onJsBeforeUnload(view, url, message, result);
    }

    // 打印 Js 中的日志 console 信息，被废弃
    @Override
    public void onConsoleMessage(String message, int lineNumber, String sourceID) {
        super.onConsoleMessage(message, lineNumber, sourceID);
    }

    // 打印 Js 中的日志 console 信息，被废弃
    @Override
    public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
        return super.onConsoleMessage(consoleMessage);
    }
}
